
-- 'Realistic' Gun base: example SWEP
-- By Teta_Bonita

if SERVER then

	AddCSLuaFile("shared.lua")
	
end

if CLIENT then

	SWEP.DrawAmmo			= true
	SWEP.DrawCrosshair		= true -- Crosshairs are for wimps.
	SWEP.ViewModelFOV		= 64
	SWEP.ViewModelFlip		= false
	SWEP.CSMuzzleFlashes	= true
		
	SWEP.Slot				= 1
	SWEP.SlotPos			= 1
	SWEP.WepSelectIcon		= surface.GetTextureID( "vgui/entities/weapon_dl-44" )
	SWEP.BounceWeaponIcon = false 
	SWEP.DrawWeaponInfoBox  = true
	
	language.Add("weapon_DL-44", "DL-44")
	killicon.Add( "weapon_Dl-44", "materials/vgui/entities/weapon_dl-44", Color(255, 220, 0, 255))
	
end

 function SWEP:Initialize()  
     self:SetWeaponHoldType("pistol")  
 end 
SWEP.Base			= "blaster_base"

------------
-- Info --
------------
SWEP.PrintName		= "DL-44"	
SWEP.Author			= "Shotgunguy49"
SWEP.Purpose		= "To shoot things, Star Wars style."
SWEP.Instructions	= "Aim away from face."


-------------
-- Misc. --
-------------
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true
SWEP.Weight				= 1.3
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false


----------------------
-- Primary Fire --
----------------------
SWEP.Primary.Damage			= 10 -- This determines both the damage dealt and force applied by the bullet.
SWEP.Primary.NumShots		= 1
SWEP.Primary.ClipSize		= 25
SWEP.Primary.DefaultClip	= 300
SWEP.Primary.Ammo			= "ar2"
SWEP.MuzzleVelocity			= 800 -- How fast the bullet travels in meters per second. 
SWEP.FiresUnderwater 		= false

-------------------------
-- BulletCallback --
-------------------------
local function BulletCallback( inflictor, attacker, tr, dmginfo )

	// perform impact effects.
	if( tr.MatType != MAT_FLESH ) then

		// hit
		if( tr.Hit && !tr.HitSky ) then
		
			// spew some flecks
			local effect = EffectData();
				effect:SetOrigin( tr.HitPos );
				effect:SetNormal( tr.HitNormal );
			util.Effect( "r_blasterImpact", effect, true, true );
			
			// decal
			util.Decal( "blaster\Nomad", tr.HitPos + tr.HitNormal * 2, tr.HitPos - tr.HitNormal * 2 );

		end
	
	end
	
	// doesn't work... oh well.
	return { damage = true, effects = false };

end
----------------------
-- Primary Attack --
----------------------
function SWEP:PrimaryAttack( )

	// next attack
	self:SetNextPrimaryFire( CurTime() + self.Primary.Delay );

	// not an npc?
	if( !self.Owner:IsNPC() ) then
	
		// enough ammo?
		if( !self:CanPrimaryAttack() ) then
		
			// sound
			self.Weapon:EmitSound( "weapons/DC-15/empty.wav" );
			
			return;
		
		end
		
		// take ammo
		if( SERVER ) then
			
			// take ammo
			self:TakePrimaryAmmo( 1 );
			
			// set next regenerate
			self.NextRegenerate = CurTime() + 0.5;
			
		end
		
	end
	self:ShootEffects()
	// create a bullet.
	local bullet = {
		Num		= 1,
		Src		= self.Owner:GetShootPos(),
		Dir		= self.Owner:GetAimVector(),
		Spread		= Vector( 0.010, 0.010, 0 ),
		Tracer		= 1,
		Force		= 10,
		Damage		= 10,
		HullSize	= HULL_TINY_CENTERED,
		AmmoType	= "ar2",
		TracerName	= "r_blasterTracer",
		Attacker	= self.Owner,
		Callback	= function( a, b, c ) return BulletCallback( self.Weapon, a, b, c ); end,
		
	};
	
	// shoot
	self.Weapon:FireBullets( bullet );
	
	// sound
	self.Weapon:EmitSound( string.format( "weapons/blaster/fire.mp3", math.random( 4 ) ) );
	

	// muzzle flash.
	local effect = EffectData();
		effect:SetOrigin( self.Owner:GetShootPos() );
		effect:SetEntity( self.Weapon );
		effect:SetAttachment( 1 );
	util.Effect( "r_blasterMuzzle", effect );

end
----------------------
-- Primary Attack Effects --
----------------------
function SWEP:ShootEffects()
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self.Owner:MuzzleFlash()
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
end
-------------------------
-- Secondary Fire --
-------------------------
-- Secondary Fire is used to switch ironsights and firemodes
SWEP.Secondary.ClipSize		= -1 -- best left at -1
SWEP.Secondary.DefaultClip	= -1 -- set to -1 if you don't use secondary ammo
SWEP.Secondary.Ammo			= "none" -- Leave this if you want your SWEP to have grenades, otherwise set to "none" if you don't use secondary ammo.


---------------------------------------
-- Recoil, Spread, and Spray --
---------------------------------------
SWEP.RecoverTime 	= 0.8 -- Time in seconds it takes the player to re-steady his aim after firing.

-- The following variables control the overall accuracy of the gun and typically increase with each shot
-- Recoil: how much the gun kicks back the player's view.
SWEP.MinRecoil		= 0.15
SWEP.MaxRecoil		= 0.5
SWEP.DeltaRecoil	= 0.15 -- The recoil to add each shot.  Same deal for spread and spray.

-- Spread: the width of the gun's firing cone.  More spread means less accuracy.
SWEP.MinSpread		= 0.002
SWEP.MaxSpread		= 0.05
SWEP.DeltaSpread	= 0.005

-- Spray: the gun's tendancy to point in random directions.  More spray means less control.
SWEP.MinSpray		= 0
SWEP.MaxSpray		= 1.4
SWEP.DeltaSpray		= 0.16


---------------------------
-- Ironsight/Scope --
---------------------------
-- IronSightsPos and IronSightsAng are model specific paramaters that tell the game where to move the weapon viewmodel in ironsight mode.

SWEP.IronSightsPos 			= Vector (-6.1052, -14.8804, 2.65)
SWEP.IronSightsAng 			= Vector (0, 0, 0)
SWEP.IronSightZoom			= 1.3 -- How much the player's FOV should zoom in ironsight mode. 
SWEP.UseScope				= true -- Use a scope instead of iron sights.
SWEP.ScopeScale 				= 0.4 -- The scale of the scope's reticle in relation to the player's screen size.
SWEP.ScopeZooms				= {8} -- The possible magnification levels of the weapon's scope.   If the scope is already activated, secondary fire will cycle through each zoom level in the table.
SWEP.DrawParabolicSights		= false -- Set to true to draw a cool parabolic sight (helps with aiming over long distances)

-------------------------
-- Effects/Visual --
-------------------------
SWEP.ViewModel				= "models/SGG/Starwars/weapons/v_dl-44.mdl"
SWEP.WorldModel				= "models/SGG/Starwars/weapons/w_dl-44.mdl"

SWEP.MuzzleEffect			= "r_blasterMuzzle" -- This is an extra muzzleflash effect

SWEP.MuzzleAttachment		= "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
SWEP.ShellEjectAttachment	= "2" -- Should be "2" for CSS models or "1" for hl2 models


-------------------
-- Modifiers --
-------------------
-- Modifiers scale the gun's recoil, spread, and spray based on the player's stance
SWEP.CrouchModifier		= 0.7 -- Applies if player is crouching.
SWEP.IronSightModifier 	= 0.7 -- Applies if player is in iron sight mode.
SWEP.RunModifier 		= 1.4 -- Applies if player is moving.
SWEP.JumpModifier 		= 1.6 -- Applies if player is in the air (jumping)

-- Note: the jumping and crouching modifiers cannot be applied simultaneously

--------------------
-- Fire Modes --
--------------------
-- You can choose from a list of firemodes, or add your own! \0/
SWEP.AvailableFireModes		= {"Semi"} -- What firemodes shall we use?
-- "Auto", "Burst", "Semi", and "Grenade" are firemodes that are available by default.

-- RPM is the rounds per minute the gun can fire for each mode (if applicable)
SWEP.AutoRPM				= 500
SWEP.DrawFireModes			= false -- Set to true to allow drawing of a visual indicator for the current firemode.

//---------- NPC Weapon
list.Set( "NPCWeapons", "weapon_dl-44", "DL-44" );
-- Yay! I hope that wasn't too confusing...

